package l1j.server.server.model.Instance;

import static l1j.server.server.model.skill.L1SkillId.BLESS_WEAPON;
import static l1j.server.server.model.skill.L1SkillId.ENCHANT_WEAPON;
import static l1j.server.server.model.skill.L1SkillId.HOLY_WEAPON;
import static l1j.server.server.model.skill.L1SkillId.SHADOW_FANG;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Timer;

import l1j.opqlo.NewSystem.ItemLevelUp.ItemLevelUp;
import l1j.opqlo.NewSystem.ItemLevelUp.ItemLevelUpTable;
import l1j.opqlo.NewSystem.ItemLevelUp.LevelStatus;
import l1j.opqlo.NewSystem.ItemStatus.ItemStatusName;
import l1j.opqlo.NewSystem.ItemStatus.L1ItemStatus;
import l1j.opqlo.NewSystem.ItemStatus.viwerName;
import l1j.opqlo.NewSystem.鑑定系統.IdentifiedTable;
import l1j.opqlo.NewSystem.鑑定系統.L1IdStatus;
import l1j.opqlo.Server.L1World.WorldItemEnchantTime;
import l1j.server.Config;
import l1j.server.server.datatables.NpcTable;
import l1j.server.server.datatables.PetTable;
import l1j.server.server.datatables.RaceTicketTable;
import l1j.server.server.model.L1EquipmentTimer;
import l1j.server.server.model.L1ItemOwnerTimer;
import l1j.server.server.model.L1Object;
import l1j.server.server.model.L1PcInventory;
import l1j.server.server.serverpackets.S_OwnCharStatus;
import l1j.server.server.templates.L1Item;
import l1j.server.server.templates.L1Npc;
import l1j.server.server.templates.L1Pet;
import l1j.server.server.templates.L1RaceTicket;

public class L1ItemInstance extends L1Object {
	private static final long serialVersionUID = 1L;

	private long _count;

	private int _itemId;

	private L1Item _item;

	private boolean _isEquipped = false;

	private int _enchantLevel;

	private boolean _isIdentified = false;

	private int _durability;

	private int _chargeCount;

	private int _remainingTime;

	private Timestamp _lastUsed = null;

	private int _lastWeight;

	private final LastStatus _lastStatus = new LastStatus();

	public boolean _isRunning = false; // 武器、裝備 魔法強化時間軸

	private int SkillTime; // 武器、裝備 魔法強化時間

	private int _bless = 1;

	private int _attrEnchantKind;

	private int _attrEnchantLevel;

	private int _FireMr = 0; // 2火

	private int _WaterMr = 0; // 4水

	private int _EarthMr = 0; // 1地

	private int _WindMr = 0; // 8風

	private int _extraDmg = 0;

	public void setExtraDmg(final int i) {
		_extraDmg = i;
	}

	public int getExtraDmg() {
		return _extraDmg;
	}

	private int _extraDef = 0;

	public void setExtraDef(final int i) {
		_extraDef = i;
	}

	public int getExtraDef() {
		return _extraDef;
	}

	private int _ModDmg = 0;

	public void setModDmg(final int i) {
		_ModDmg = i;
	}

	public int getModDmg() {
		return _ModDmg;
	}

	private int _ModHit = 0;

	public void setModHit(final int i) {
		_ModHit = i;
	}

	public int getModHit() {
		return _ModHit;
	}

	private int _DoubleDmg = 0;

	public void setDoubleDmg(final int chance) {
		_DoubleDmg = chance;
	}

	public int getDoubleDmg() {
		return _DoubleDmg;
	}

	private double _expUp = 0;

	public void setExpUp(final double d) {
		_expUp = d;
	}

	public double getExpUp() {
		return _expUp;
	}

	private int _Big = 0;
	private int _Small = 0;

	public void setBigDmg(final int i) {
		_Big = i ;
	}

	public int getBigDmg() {
		return _Big;
	}

	public void setSmallDmg(final int i) {
		_Small = i;
	}

	public int getSmallDmg() {
		return _Small;
	}

	private int _addMr = 0;

	public void setaddMr(final int i) {
		_addMr = i;
	}

	public int getaddMr() {
		return _addMr;
	}

	private int _Mpr = 0;

	private int _Hpr = 0;

	private int _addHp = 0;

	private int _addMp = 0;

	private int _addSp = 0;

	private int _SkillType = 0;// TODO 魔法武器卷軸by missu0524

	private boolean proctect = false;// TODO 裝備保護卷軸 by missu0524

	private int _acByMagic = 0;

	private int _dmgByMagic = 0;

	private int _holyDmgByMagic = 0;

	private int _hitByMagic = 0;

	private L1PcInstance _itemMaster;

	private int _itemOwnerId = 0;

	private L1EquipmentTimer _equipmentTimer;

	private boolean _isNowLighting = false;

	private Timestamp _deleteDate;

	public L1ItemInstance() {
		_count = 1;
		_enchantLevel = 0;
	}

	public L1ItemInstance(final L1Item item, final long l) {
		this();
		setItem(item);
		setCount(l);

	}

	/**
	 * アイテムが確認(鑑定)済みであるかを返す。
	 * 
	 * @return 確認済みならtrue、未確認ならfalse。
	 */
	public boolean isIdentified() {
		return _isIdentified;
	}

	/**
	 * アイテムが確認(鑑定)済みであるかを設定する。
	 * 
	 * @param identified
	 *            確認済みならtrue、未確認ならfalse。
	 */
	public void setIdentified(final boolean identified) {
		_isIdentified = identified;
	}

	public String getName() {
		return _item.getName();
	}

	/**
	 * アイテムの個数を返す。
	 * 
	 * @return アイテムの個数
	 */
	public long getCount() {
		return _count;
	}

	/**
	 * アイテムの個数を設定する。
	 * 
	 * @param count
	 *            アイテムの個数
	 */
	public void setCount(final long count) {
	/*	if(getItemId() == L1ItemId.ADENA){
			long newcount = _count  + count;
			if(newcount >= L1Inventory.MAX_AMOUNT){
				final L1ItemInstance item2 = ItemTable.getInstance().createItem(60308);
				if (item2 != null) {
					final int itemcount2 = (int) (newcount / 100000000);
					item2.setCount(itemcount2);
					getItemMaster().getInventory().storeItem(item2);
					getItemMaster().sendPackets(new S_ServerMessage(403, item2.getLogName()));
					_count=Math.max(1, _count-(itemcount2 * 100000000));
					return;
				}
			}
		}*/
		final long newcount = Math.min(2000000000, (count));
		_count = newcount;
	}

	/**
	 * アイテムが装備されているかを返す。
	 * 
	 * @return アイテムが装備されていればtrue、装備されていなければfalse。
	 */
	public boolean isEquipped() {
		return _isEquipped;
	}

	/**
	 * アイテムが装備されているかを設定する。
	 * 
	 * @param equipped
	 *            アイテムが装備されていればtrue,装備されていなければfalse。
	 */
	public void setEquipped(final boolean equipped) {
		_isEquipped = equipped;
	}

	public L1Item getItem() {
		return _item;
	}

	public void setItem(final L1Item item) {
		_item = item;
		_itemId = item.getItemId();
	}

	public int getItemId() {
		return _itemId;
	}

	public void setItemId(final int itemId) {
		_itemId = itemId;
	}

	public boolean isStackable() {
		return _item.isStackable();
	}

	@Override
	public void onAction(final L1PcInstance player) {
	}

	public int getEnchantLevel() {
		return _enchantLevel;
	}

	public void setEnchantLevel(final int enchantLevel) {
		_enchantLevel = enchantLevel;
	}

	public int get_gfxid() {
		return _item.getGfxId();
	}

	public int get_durability() {
		return _durability;
	}

	public int getChargeCount() {
		return _chargeCount;
	}

	public void setChargeCount(final int i) {
		_chargeCount = i;
	}

	public int getRemainingTime() {
		return _remainingTime;
	}

	public void setRemainingTime(final int i) {
		_remainingTime = i;
	}

	public void setLastUsed(final Timestamp t) {
		_lastUsed = t;
	}

	public Timestamp getLastUsed() {
		return _lastUsed;
	}

	public int getLastWeight() {
		return _lastWeight;
	}

	public void setLastWeight(final int weight) {
		_lastWeight = weight;
	}

	public void setBless(final int i) {
		_bless = i;
	}

	public int getBless() {
		return _bless;
	}

	public void setAttrEnchantKind(final int i) {
		_attrEnchantKind = i;
	}

	public int getAttrEnchantKind() {
		return _attrEnchantKind;
	}

	public void setAttrEnchantLevel(final int i) {
		_attrEnchantLevel = i;
	}

	public int getAttrEnchantLevel() {
		return _attrEnchantLevel;
	}

	public int getMr() {
		final int mr = _item.get_mdef();
		switch (getItemId()) {
		case 20011:
		case 20110:
		case 21108:
		case 120011:
			return mr + getEnchantLevel();

		case 20056:
		case 120056:
		case 220056:
			return mr + getEnchantLevel() * 2;

		default:
			return mr;
		}

	}

	/*
	 * 耐久性、0~127まで -の値は許可しない。
	 */
	public void set_durability(int i) {
		i = Math.max(0, i);
		i = Math.min(127, i);
		_durability = i;
	}

	public int getWeight() {
		if (getItem().getWeight() == 0) {
			return 0;
		} else {
			return (int) Math.max(getCount() * getItem().getWeight() / 1000, 1);
		}
	}

	/**
	 * 前回DBへ保存した際のアイテムのステータスを格納するクラス
	 */
	public class LastStatus {

		// TODO 飾品強化卷軸
		public int firemr;
		public int watermr;
		public int earthmr;
		public int windmr;
		public int addhp;
		public int addmp;
		public int hpr;
		public int mpr;
		public int addsp;
		// TODO 飾品強化卷軸

		// TODO 魔法武器卷軸by missu0524
		public int skilltype;
		// TODO 魔法武器卷軸by missu0524

		public String 屬性增傷;
		public String 種族增傷;
		public String 六屬性加成;
		public long count;

		public int itemId;

		public boolean isEquipped = false;

		public int enchantLevel;

		public boolean isIdentified = true;

		public int durability;

		public int chargeCount;

		public int remainingTime;

		public Timestamp lastUsed = null;

		public int bless;

		public int attrEnchantKind;

		public int attrEnchantLevel;

		public Timestamp DeleteDate; // opqlo 道具天數刪除系統

		public int level;
		
		public double exp;

		public int extradmg;
		public int extradef;
		public int moddmg;
		public int modhit;
		public int doubledmg;
		public double bigdmg;
		public double smalldmg;
		public int addmr;
		public int stundice;
		public int stonedice;
		public int sleepdice;
		public int freezedice;
		public int sustaindice;
		public int blindice;
		
		public void updateAll() {
			屬性增傷 = getLvStatus().saveItemSpecialDmg(0);
			種族增傷 = getLvStatus().saveItemSpecialDmg(2);
			六屬性加成 =getLvStatus().saveItemSpecialDmg(1);
			extradmg = getExtraDmg();
			extradef =getExtraDef();
			moddmg = getModDmg();
			modhit = getModHit();
			doubledmg = getDoubleDmg();
			bigdmg = getBigDmg();
			smalldmg = getSmallDmg();
			addmr = getaddMr();
			stundice = getStunDice();
			stonedice = getStoneDice();
			sleepdice = getSleepDice();
			freezedice = getFreezeDice();
			sustaindice = getSustainDice();
			blindice = getBlindDice();
			exp = getExpUp();
			count = getCount();
			itemId = getItemId();
			isEquipped = isEquipped();
			isIdentified = isIdentified();
			enchantLevel = getEnchantLevel();
			durability = get_durability();
			chargeCount = getChargeCount();
			remainingTime = getRemainingTime();
			lastUsed = getLastUsed();
			bless = getBless();
			attrEnchantKind = getAttrEnchantKind();
			attrEnchantLevel = getAttrEnchantLevel();
			// TODO 飾品強化卷軸
			firemr = getFireMr();
			watermr = getWaterMr();
			earthmr = getEarthMr();
			windmr = getWindMr();
			addhp = getaddHp();
			addmp = getaddMp();
			addsp = getaddSp();
			hpr = getHpr();
			mpr = getMpr();
			// TODO 飾品強化卷軸

			// TODO 魔法武器卷軸by missu0524
			skilltype = getSkillType();
			// TODO 魔法武器卷軸by missu0524
			DeleteDate = getDeleteDate(); // 道具天數刪除系統
			level = getLevel();// opqlo 道具升級系統
		}

		// TODO 飾品強化卷軸
		public void updateFireMr() {
			firemr = getFireMr();
		}

		public void updateWaterMr() {
			watermr = getWaterMr();
		}

		public void updateEarthMr() {
			earthmr = getEarthMr();
		}

		public void updateWindMr() {
			windmr = getWindMr();
		}

		public void updateSp() {
			addsp = getaddSp();
		}

		public void updateaddHp() {
			addhp = getaddHp();
		}

		public void updateaddMp() {
			addmp = getaddMp();
		}

		public void updateHpr() {
			hpr = getHpr();
		}

		public void updateMpr() {
			mpr = getMpr();
		}

		// TODO 飾品強化卷軸
		public void updateCount() {
			count = getCount();
		}

		// opqlo 道具升級系統
		public void updateLevel() {
			level = getLevel();
		}

		// TODO 魔法武器卷軸by missu0524
		public void updateSkillType() {
			skilltype = getSkillType();
		}
		
		public void update屬性增傷(){
			屬性增傷 = getLvStatus().saveItemSpecialDmg(0);
		}
		public void update種族增傷(){
		種族增傷 = getLvStatus().saveItemSpecialDmg(2);
		}
		public void update六屬性加成(){
		六屬性加成 =getLvStatus().saveItemSpecialDmg(1);
		}
		
		public void updateExp(){
			exp = getExpUp();
		}

		// TODO 魔法武器卷軸by missu0524
		public void updateItemId() {
			itemId = getItemId();
		}

		// opqlo 道具天數刪除系統
		public void updateDeleteDate() {
			DeleteDate = getDeleteDate();
		}

		public void updateEquipped() {
			isEquipped = isEquipped();
		}

		public void updateIdentified() {
			isIdentified = isIdentified();
		}

		public void updateEnchantLevel() {
			enchantLevel = getEnchantLevel();
		}

		public void updateDuraility() {
			durability = get_durability();
		}

		public void updateChargeCount() {
			chargeCount = getChargeCount();
		}

		public void updateRemainingTime() {
			remainingTime = getRemainingTime();
		}

		public void updateLastUsed() {
			lastUsed = getLastUsed();
		}

		public void updateBless() {
			bless = getBless();
		}

		public void updateAttrEnchantKind() {
			attrEnchantKind = getAttrEnchantKind();
		}

		public void updateAttrEnchantLevel() {
			attrEnchantLevel = getAttrEnchantLevel();
		}

		public void updateBlindDice() {
			blindice = getBlindDice();
		}

		public void updateSustainDice() {
			sustaindice = getSustainDice();
		}

		public void updateFreezeDice() {
			freezedice = getFreezeDice();
		}

		public void updateSleepDice() {
			sleepdice = getSleepDice();
		}

		public void updateStoneDice() {
			stonedice = getStoneDice();
		}

		public void updateStunDice() {
			stundice = getStunDice();
		}

		public void updateaddMr() {
			addmr = getaddMr();
		}

		public void updateSmallDmg() {
			smalldmg = getSmallDmg();
		}

		public void updateBigDmg() {
			bigdmg = getBigDmg();
		}

		public void updateDoubleDmg() {
			doubledmg = getDoubleDmg();
		}

		public void updateModHit() {
			modhit = getModHit();
		}

		public void updateModDmg() {
			moddmg = getModDmg();
		}

		public void updateExtraDef() {
			extradef =getExtraDef();
		}

		public void updateExtraDmg() {
			extradmg = getExtraDmg();
		}
	}

	public LastStatus getLastStatus() {
		return _lastStatus;
	}

	/**
	 * 前回DBに保存した時から変化しているカラムをビット集合として返す。
	 */
	public int getRecordingColumns() {
		int column = 0;

		if (getCount() != _lastStatus.count) {
			column += L1PcInventory.COL_COUNT;
		}
		if (getItemId() != _lastStatus.itemId) {
			column += L1PcInventory.COL_ITEMID;
		}
		if (isEquipped() != _lastStatus.isEquipped) {
			column += L1PcInventory.COL_EQUIPPED;
		}
		if (getEnchantLevel() != _lastStatus.enchantLevel) {
			column += L1PcInventory.COL_ENCHANTLVL;
		}
		if (get_durability() != _lastStatus.durability) {
			column += L1PcInventory.COL_DURABILITY;
		}
		if (getChargeCount() != _lastStatus.chargeCount) {
			column += L1PcInventory.COL_CHARGE_COUNT;
		}
		if (getLastUsed() != _lastStatus.lastUsed) {
			column += L1PcInventory.COL_DELAY_EFFECT;
		}
		if (isIdentified() != _lastStatus.isIdentified) {
			column += L1PcInventory.COL_IS_ID;
		}
		if (getRemainingTime() != _lastStatus.remainingTime) {
			column += L1PcInventory.COL_REMAINING_TIME;
		}
		if (getBless() != _lastStatus.bless) {
			column += L1PcInventory.COL_BLESS;
		}
		if (getAttrEnchantKind() != _lastStatus.attrEnchantKind) {
			column += L1PcInventory.COL_ATTR_ENCHANT_KIND;
		}
		if (getAttrEnchantLevel() != _lastStatus.attrEnchantLevel) {
			column += L1PcInventory.COL_ATTR_ENCHANT_LEVEL;
		}

		// TODO 飾品強化卷軸
		if (getFireMr() != _lastStatus.firemr) {
			column += L1PcInventory.COL_FIREMR;
		}
		if (getWaterMr() != _lastStatus.watermr) {
			column += L1PcInventory.COL_WATERMR;
		}
		if (getEarthMr() != _lastStatus.earthmr) {
			column += L1PcInventory.COL_EARTHMR;
		}
		if (getWindMr() != _lastStatus.windmr) {
			column += L1PcInventory.COL_WINDMR;
		}
		if (getaddSp() != _lastStatus.addsp) {
			column += L1PcInventory.COL_ADDSP;
		}
		if (getaddHp() != _lastStatus.addhp) {
			column += L1PcInventory.COL_ADDHP;
		}
		if (getaddMp() != _lastStatus.addmp) {
			column += L1PcInventory.COL_ADDMP;
		}
		if (getHpr() != _lastStatus.hpr) {
			column += L1PcInventory.COL_HPR;
		}
		if (getMpr() != _lastStatus.mpr) {
			column += L1PcInventory.COL_MPR;
		}
		// TODO 飾品強化卷軸

		// TODO 魔法武器卷軸by missu0524
		if (getSkillType() != _lastStatus.skilltype) {
			column += L1PcInventory.COL_SKILLTYPE;
		}
		// TODO 魔法武器卷軸by missu0524

		// opqlo 道具天數刪除系統
		if (getDeleteDate() != _lastStatus.DeleteDate) {
			column += L1PcInventory.COL_DELETE_DATE;
		}
		if (getLevel() != _lastStatus.level) {
			column += L1PcInventory.COL_LEVEL;
		}

		return column;
	}

	/**
	 * 鞄や倉庫で表示される形式の名前を個数を指定して取得する。<br>
	 */
	public String getNumberedViewName(final long count) {
		final StringBuilder name = new StringBuilder(getNumberedName(count));
		final int itemType2 = getItem().getType2();
		final int itemId = getItem().getItemId();

		if (itemId == 40314 || itemId == 40316) { // ペットのアミュレット
			final L1Pet pet = PetTable.getInstance().getTemplate(getId());
			if (pet != null) {
				final L1Npc npc = NpcTable.getInstance().getTemplate(
						pet.get_npcid());
				// name.append("[Lv." + pet.get_level() + " "
				// + npc.get_nameid() + "]");
				name.append("[Lv.").append(pet.get_level()).append(" ").append(pet.get_name()).append("]HP").append(pet.get_hp()).append(" ").append(npc.get_nameid());
			}

			// 賭狗
		} else if (itemId == 40309) {
			final L1RaceTicket ticket = RaceTicketTable.getInstance().getTemplate(getId());
			if (ticket != null) {
				name.delete(0, name.length());
				name.append("賭票 ");
				name.append(" ");
				name.append(ticket.get_round());
				name.append("-");
				name.append(ticket.get_runner_name());
				name.append(" (");
				name.append(count);
				name.append(")");
			}

			// 賭狗
		} else if (getItem().getType2() == 0 && getItem().getType() == 2) { // light系アイテム
			if (isNowLighting()) {
				name.append(" ($10)");
			}
			if (itemId == 40001 || itemId == 40002) { // ランプorランタン
				if (getRemainingTime() <= 0) {
					name.append(" ($11)");
				}
			}
		}

		if (isEquipped()) {
			if (itemType2 == 1) {
				name.append(" ($9)"); // 装備(Armed)
			} else if (itemType2 == 2) {
				name.append(" ($117)"); // 装備(Worn)
			} else if (itemType2 == 0 && getItem().getType() == 11) { // petitem
				name.append(" ($117)"); // 装備(Worn)
			}
		}
		// opqlo 道具天數刪除系統
		if (getDeleteDate() != null) {
			SimpleDateFormat sdf = new SimpleDateFormat("MM/dd-HH:mm");
			String fm = sdf.format(getDeleteDate().getTime());
			name.append("\n期限:[" + fm + "]");
		}
		final viwerName Name = new viwerName();

		String viwername = Name.getViwerName(this);
		if(viwername!=null){
			name.append("\n"+"	\\f="+viwername);

		}


		return name.toString();
	}

	/**
	 * 鞄や倉庫で表示される形式の名前を返す。<br>
	 * 例:+10 カタナ (装備)
	 */
	public String getViewName() {
		return getNumberedViewName(_count);
	}

	/**
	 * ログに表示される形式の名前を返す。<br>
	 * 例:アデナ(250) / +6 ダガー
	 */
	public String getLogName() {
		return getNumberedName(_count);
	}

	/**
	 * ログに表示される形式の名前を、個数を指定して取得する。
	 */
	public String getNumberedName(final long count) {
		final StringBuilder name = new StringBuilder();
		final int type2 = getItem().getType2() ;
		if(proctect){
			name.append("(防爆) ");
		}
		if (isIdentified()) {
			if (type2 == 1 || type2 == 2) { // 武器・防具
				if (getEnchantLevel() >= 0) {
					name.append("+").append(getEnchantLevel()).append(" ");
				} else if (getEnchantLevel() < 0) {
					name.append(String.valueOf(getEnchantLevel())).append(" ");
				}
				if (type2 == 1) { // 武器
					if (_attrEnchantLevel > 0) {
						name.append(ItemStatusName.get().getAttrKindName(_attrEnchantKind, _attrEnchantLevel));
					}
				}

				//opqlo 道具升級系統START
				final ItemLevelUp uu =ItemLevelUpTable.getInstance().getTemplate(_itemId);
				final int level = getLevel();
				if(uu !=null && level>1){ //opqlo 種族相剋
					if(uu.getIsCanSee()){ //opqlo 是否顯示等級
						name.append("Lv").append(level);
					}else{
						if(_itemId >=810008 && _itemId <=810024){
							name.append("數值").append((level-1)).append(" ");
						}
					}
				}
			}
			if(getBless()==0){
				name.append("受祝福的 ");
			}
			//	}
			//TODO 魔法武器卷軸by missu0524
			/*	if (isIdentified() && getItem().getType2() == 1 ) {
			if (getSkillType() == 1){
				name.append("\\fD噬血");}
			else if (getSkillType() == 2){
				name.append("\\fV冥魔");}
			else if (getSkillType() == 3){
				name.append("\\f=冰雨");}
			else if (getSkillType() == 4){
				name.append("\\fS光爆");}
		}*/
			//TODO 魔法武器卷軸by missu0524

			name.append(_item.getIdentifiedNameId());

			if (getItem().getMaxChargeCount() > 0 || getChargeCount() >0) {
				if(getItemId()==780046 || getItemId()==780047){
					name.append(" +").append(getChargeCount());
				}else{
					name.append(" (").append(getChargeCount()).append(")");
				}
			}else if (getItem().getItemId() == 20383) { // 騎馬用ヘルム
				name.append(" (").append(getChargeCount()).append(")");

				//if (getItem().getMaxUseTime() > 0 && type2 != 0) { // 武器防具で使用時間制限あり
			}else if (getRemainingTime() > 0 && type2 != 0) { // 武器防具で使用時間制限あり
				name.append(" (").append(getRemainingTime()).append(")");
			}
		} else {
			name.append(_item.getUnidentifiedNameId());
			final L1IdStatus status =IdentifiedTable.getInstance().getIdentified(_itemId);
			if(status != null){
				name.append(" 鑑定:[").append(status.getStatusCount()).append(" / ").append(Math.min(100, (int)(status.getChance()*Config.IDENTIFIED_RATE))).append("%]");
			}
		}

		if (count > 1) {
			name.append(" (").append(count).append(")");
		}

		return name.toString();
	}

	// TODO 飾品強化卷軸

	public int getFireMr() {
		return _FireMr;
	}

	public void setFireMr(final int i) {
		_FireMr = i;
	}

	public int getWaterMr() {
		return _WaterMr;
	}

	public void setWaterMr(final int i) {
		_WaterMr = i;
	}

	public int getEarthMr() {
		return _EarthMr;
	}

	public void setEarthMr(final int i) {
		_EarthMr = i;
	}

	public int getWindMr() {
		return _WindMr;
	}

	public void setWindMr(final int i) {
		_WindMr = i;
	}

	public int getMpr() {
		return _Mpr;
	}

	public void setMpr(final int i) {
		_Mpr = i;
	}

	public int getHpr() {
		return _Hpr;
	}

	public void setHpr(final int i) {
		_Hpr = i;
	}

	public int getaddHp() {
		return _addHp;
	}

	public void setaddHp(final int i) {
		_addHp = i;
	}

	public int getaddMp() {
		return _addMp;
	}

	public void setaddMp(final int i) {
		_addMp = i;
	}

	public int getaddSp() {
		return _addSp;
	}

	public void setaddSp(final int i) {
		_addSp = i;
	}

	// TODO 飾品強化卷軸

	public int getSkillType() {
		return _SkillType;
	}

	public void setSkillType(final int i) {
		_SkillType = i;
	}

	public boolean getproctect() {
		return proctect;
	}

	public void setproctect(final boolean i) {
		proctect = i;
	}

	// TODO 裝備保護卷軸 by missu0524

	/**
	 * 物品詳細資料
	 */
	public byte[] getStatusBytes() {
		final L1ItemStatus itemInfo = new L1ItemStatus(this);
		return itemInfo.getStatusBytes().getBytes();
	}

	public int getAcByMagic() {
		return _acByMagic;
	}

	public void setAcByMagic(final int i) {
		_acByMagic = i;
	}

	public int getDmgByMagic() {
		return _dmgByMagic;
	}

	public void setDmgByMagic(final int i) {
		_dmgByMagic = i;
	}

	public int getHolyDmgByMagic() {
		return _holyDmgByMagic;
	}

	public void setHolyDmgByMagic(final int i) {
		_holyDmgByMagic = i;
	}

	public int getHitByMagic() {
		return _hitByMagic;
	}

	public void setHitByMagic(final int i) {
		_hitByMagic = i;
	}

	/** opqlo 武器防具強化時間軸 */
	public void addSkillTime(final int i) {
		SkillTime += i;
	}

	/** opqlo 武器防具強化時間軸 */
	public int getSkillTime() {
		return SkillTime;
	}

	public L1PcInstance getItemMaster() {
		return _itemMaster;
	}

	/**
	 * 盔甲強化時間軸
	 * 
	 * @param pc
	 * @param skillId
	 * @param skillTime
	 */
	public void setSkillArmorEnchant(final L1PcInstance pc, final int skillId,
			final int skillTime) {

		if (pc == null || pc.isDead()) {
			return;
		}

		final int type = getItem().getType();
		final int type2 = getItem().getType2();
		if (_isRunning) {
			_itemMaster = pc; // opqlo
			SkillTime = skillTime;// opqlo
			return;
		}
		if (type == 2 && type2 == 2 && isEquipped()) {
			pc.addAc(-3);
			pc.sendPackets(new S_OwnCharStatus(pc));
		}
		setAcByMagic(3);
		_itemMaster = pc; // opqlo
		SkillTime = skillTime;// opqlo
		_isRunning = true;
		WorldItemEnchantTime.get().put(new Integer(this.getId()), (L1ItemInstance) this);// opqlo
	}

	/**
	 * 武器強化時間軸
	 * 
	 * @param pc
	 * @param skillId
	 * @param skillTime
	 */
	public void setSkillWeaponEnchant(final L1PcInstance pc, final int skillId,
			final int skillTime) {
		if (getItem().getType2() != 1) {
			return;
		}
		if (pc == null || pc.isDead()) {
			return;
		}
		if (_isRunning) {
			_itemMaster = pc; // opqlo
			SkillTime = skillTime;// opqlo
			return;
		}

		switch (skillId) {
		case HOLY_WEAPON:
			setHolyDmgByMagic(1);
			setHitByMagic(1);
			break;

		case ENCHANT_WEAPON:
			setDmgByMagic(2);
			break;

		case BLESS_WEAPON:
			setDmgByMagic(2);
			setHitByMagic(2);
			break;

		case SHADOW_FANG:
			setDmgByMagic(5);
			break;

		default:
			break;
		}

		_itemMaster = pc; // opqlo
		SkillTime = skillTime;// opqlo
		_isRunning = true;
		WorldItemEnchantTime.get().put(new Integer(this.getId()), (L1ItemInstance) this);// opqlo

	}

	public int getItemOwnerId() {
		return _itemOwnerId;
	}

	public void setItemOwnerId(final int i) {
		_itemOwnerId = i;
	}

	public void startItemOwnerTimer(final L1PcInstance pc) {
		setItemOwnerId(pc.getId());
		final L1ItemOwnerTimer timer = new L1ItemOwnerTimer(this, 10000);
		timer.begin();
	}

	/**
	 * 計時物件啟用
	 * 
	 * @param pc
	 */
	public void startEquipmentTimer(final L1PcInstance pc) {
		if (getRemainingTime() > 0) {
			_equipmentTimer = new L1EquipmentTimer(pc, this);
			final Timer timer = new Timer(true);
			timer.scheduleAtFixedRate(_equipmentTimer, 1000, 1000);
		}
	}

	/**
	 * 計時物件停止計時
	 * 
	 * @param pc
	 */
	public void stopEquipmentTimer(final L1PcInstance pc) {
		if (getRemainingTime() > 0) {
			_equipmentTimer.cancel();
			_equipmentTimer = null;
		}
	}

	public boolean isNowLighting() {
		return _isNowLighting;
	}

	public void setNowLighting(final boolean flag) {
		_isNowLighting = flag;
	}

	// opqlo 道具天數刪除系統

	public Timestamp getDeleteDate() {
		return _deleteDate;
	}

	public void setDeleteDate(Timestamp time) {
		_deleteDate = time;
	}

	// opqlo 道具升級系統START
	private int _level = 1;

	public int getLevel() {
		return _level;
	}

	public void setLevel(final int i) {
		_level = i;
	}

	public void addLevel(final int i) {
		_level += i;
	}

	private LevelStatus _LvStatus = new LevelStatus();

	public LevelStatus getLvStatus() {
		return _LvStatus;
	}

	//暈眩機率增加
	private int _Stundice = 0;
	public void setStunDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Stundice = dice;
	}
	public int getStunDice(){
		return _Stundice;
	}
	// 石化機率增加
	private int _Stonedice = 0;
	public void setStoneDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Stonedice = dice;
	}
	public int getStoneDice(){
		return _Stonedice;
	}
	// 睡眠增加機率
	private int _Sleepdice = 0;
	public void setSleepDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Sleepdice = dice;
	}
	public int getSleepDice(){
		return _Sleepdice;
	}
	//增加凍結機率
	private int _Freezedice = 0;
	public void setFreezeDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Freezedice = dice;
	}
	public int getFreezeDice(){
		return _Freezedice;
	}

	// 支撐機率增加
	private int _Sustaindice = 0;
	public void setSustainDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Sustaindice = dice;
	}
	public int getSustainDice(){
		return _Sustaindice;
	}
	//增加暗黑機率
	private int _Blinddice = 0;
	public void setBlindDice(int dice){
		dice = Math.min(100, dice);
		dice = Math.max(dice, 0);
		_Blinddice = dice;
	}
	public int getBlindDice(){
		return _Blinddice;
	}
	//暈眩抵抗增加
	private int _StunMr = 0;
	public void setStunMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_StunMr = Mr;
	}
	public int getStunMr(){
		return _StunMr;
	}
	// 石化抵抗增加
	private int _StoneMr = 0;
	public void setStoneMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_StoneMr = Mr;
	}
	public int getStoneMr(){
		return _StoneMr;
	}
	// 睡眠增加抵抗
	private int _SleepMr = 0;
	public void setSleepMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_SleepMr = Mr;
	}
	public int getSleepMr(){
		return _SleepMr;
	}
	//增加凍結抵抗
	private int _FreezeMr = 0;
	public void setFreezeMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_FreezeMr = Mr;
	}
	public int getFreezeMr(){
		return _FreezeMr;
	}

	// 支撐抵抗增加
	private int _SustainMr = 0;
	public void setSustainMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_SustainMr = Mr;
	}
	public int getSustainMr(){
		return _SustainMr;
	}
	//增加暗黑抵抗
	private int _BlindMr = 0;
	public void setBlindMr(int Mr){
		Mr = Math.min(100, Mr);
		Mr = Math.max(Mr, 0);
		_BlindMr = Mr;
	}
	public int getBlindMr(){
		return _BlindMr;
	}
	/**opqlo 掉寶率*/

	private double _droprate;

	public void addDroprate(final double i){
		_droprate += (i / 100);
	}

	public double getDroprate(){
		return _droprate;
	}
	/** opqlo 魔法增傷**/
	private int _magicDmgMod;
	/** opqlo 魔法增傷**/
	public void setMagicDmgMod(final int i){
		_magicDmgMod = i;
	}
	/** opqlo 魔法增傷**/
	public int getMagicDmgMod(){
		return _magicDmgMod;
	}

	/**opqlo 掉寶率*/
}
